package org.example.controller.admin;


import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.example.entity.Shanpin;
import org.example.result.Result;
import org.example.service.ShouchanService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/admin/shouchan")
@Slf4j
@Api(tags = "商品收藏相关接口")
public class EmployeeshouchanController {

    @Autowired
    ShouchanService shouchanService;

    /**
     * 商品收藏查询
     *
     * @param
     * @return
     */
    @GetMapping("/cx")
    @ApiOperation(value = "商品收藏查询")
    public Result cx(@RequestParam("id") int id,
                     @RequestParam("username") String username) {
        log.info("商品收藏查询：{}", id);
        if (shouchanService.cx(id, username) != null) {
            return Result.success();
        } else {
            return Result.error("失败");
        }

    }


    /**
     * 商品收藏修改
     *
     * @param
     * @return
     */
    @PutMapping("/xg")
    @ApiOperation(value = "商品收藏修改")
    public Result xg(@RequestParam("id") int id, @RequestParam("isFavorite") Boolean isFavorite,
                     @RequestParam("username") String username) {
        log.info("商品收藏修改：{}", id);
        shouchanService.xg(id, isFavorite, username);
        return Result.success();

    }


    /**
     * 商品收藏商品查询
     *
     * @param
     * @return
     */
    @GetMapping("/shanpincx")
    @ApiOperation(value = "商品收藏商品查询")
    public Result<List<Shanpin>> shanpincx(@RequestParam("username") String username) {
        log.info("商品收藏商品查询：{}");

        return Result.success(shouchanService.shanpincx(username));

    }

    /**
     * 收藏删除
     *
     * @param
     * @return
     */
    @DeleteMapping("/sc")
    @ApiOperation(value = "收藏删除")
    public Result shouchansc(@RequestParam("id") int id
            , @RequestParam("username") String username) {
        log.info("收藏删除：{}", id);
        shouchanService.sc(id, username);
        return Result.success();
    }

}
